//
//  MSMemberTableFooterView.m
//  SocietySale
//
//  Created by yumingwei on 2016/11/27.
//  Copyright © 2016年 Mike. All rights reserved.
//

#import "MSMemberTableFooterView.h"

@interface MSMemberTableFooterView () <UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) UICollectionView *collectionView;
@end

@implementation MSMemberTableFooterView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self initUI];
    }
    return self;
}

- (void)initUI{
    [self creatData];
    
    UILabel *titleLabel = [self creatLabel:CGRectMake(12, 10, SCREEN_WIDTH-24, 20)];
    titleLabel.text = @"可以通过以下方式获取江湖币：";
    
    NSArray *array = @[@"去发布交易",@"邀请通讯录好友"];
    for (int i = 0; i<array.count; i++) {
        UIButton *getBtn = [[UIButton alloc] initWithFrame:CGRectMake(20+i*(20+(SCREEN_WIDTH-60)/2), titleLabel.bottom+10, (SCREEN_WIDTH-60)/2, 35)];
        getBtn.tag = 10+i;
        getBtn.titleLabel.font = HeitiFont(15);
        [getBtn setTitle:array[i] forState:UIControlStateNormal];
        [getBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        getBtn.layer.cornerRadius = 2;
        getBtn.layer.borderWidth = 0.8;
        getBtn.layer.borderColor = kNormalGray.CGColor;
        [getBtn addTarget:self action:@selector(getClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:getBtn];
    }
    
    UILabel *titleLabel2 = [self creatLabel:CGRectMake(12, titleLabel.bottom+65, SCREEN_WIDTH-24, 20)];
    titleLabel2.text = @"或者通过以下方式分享：";
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.itemSize = CGSizeMake(84, 70);
    flowLayout.minimumLineSpacing = 0;
    flowLayout.minimumInteritemSpacing = 0;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, titleLabel2.bottom+15, SCREEN_WIDTH, 70) collectionViewLayout:flowLayout];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    self.collectionView.scrollsToTop = NO;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.showsVerticalScrollIndicator = NO;
    [self addSubview:self.collectionView];
    
    [self.collectionView registerClass:[MSShareCollectionCell class] forCellWithReuseIdentifier:@"ShareCollectionCell"];
}

//创建label
- (UILabel*)creatLabel:(CGRect)frame{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.font = HeitiFont(14);
    label.textColor = kLightGrayColor;
    [self addSubview:label];
    return label;
}

- (void)creatData{
    MSCommonModel *model = [[MSCommonModel alloc] init];
    model.title = @"新浪微博";
    model.thirdTitle = @"weibo";
    
    MSCommonModel *model1 = [[MSCommonModel alloc] init];
    model1.title = @"微信好友";
    model1.thirdTitle = @"weixin";
    
    MSCommonModel *model2 = [[MSCommonModel alloc] init];
    model2.title = @"朋友圈";
    model2.thirdTitle = @"pengyouquan";
    
    MSCommonModel *model3 = [[MSCommonModel alloc] init];
    model3.title = @"QQ好友";
    model3.thirdTitle = @"qq";
    
    MSCommonModel *model4 = [[MSCommonModel alloc] init];
    model4.title = @"QQ空间";
    model4.thirdTitle = @"qzone";
    
    MSCommonModel *model5 = [[MSCommonModel alloc] init];
    model5.title = @"腾讯微博";
    model5.thirdTitle = @"tengxunweibo";
    
    self.dataArray = [@[model,model1,model2,model3,model4,model5] mutableCopy];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    MSShareCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ShareCollectionCell" forIndexPath:indexPath];
    cell.model = self.dataArray[indexPath.row];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if ([self.delegate respondsToSelector:@selector(tableFooterViewSelectBtnWithIndex:)]) {
        [self.delegate tableFooterViewSelectBtnWithIndex:indexPath.row];
    }
    
}

- (void)getClick:(UIButton*)btn{
    if ([self.delegate respondsToSelector:@selector(tableFooterViewSelectBtnWithIndex:)]) {
        [self.delegate tableFooterViewSelectBtnWithIndex:btn.tag];
    }
}

@end


@interface MSShareCollectionCell ()
@property (nonatomic, strong) DOImageView *iconImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@end

@implementation MSShareCollectionCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView {
    self.iconImageView = [[DOImageView alloc] initWithFrame:CGRectMake(20, 0, 44, 44)];
    [self.contentView addSubview:self.iconImageView];
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.iconImageView.bottom+5, self.width, 20)];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = HeitiFont(13);
    self.titleLabel.textColor = [UIColor blackColor];
    [self.contentView addSubview:self.titleLabel];
}

- (void)setModel:(MSCommonModel *)model {
    _model = model;
    self.iconImageView.imgURLStr = model.thirdTitle;
    self.titleLabel.text = model.title;
}

@end

